<template>
  <div class="wapper">
    <el-container style="100%">
      <el-main style="background:#fff;">
        <div class="table-wrap" v-show="listShow">
          <div class="handle-box3">
            <el-form :inline="true" ref="form" :model="searchForm" class="demo-form-inline">
              <div class="uers-left">
                <span style="padding-left:10px">
                <el-form-item label="微信查票地址：">
                   <el-tag type="primary">{{this.url1}}</el-tag>
                </el-form-item>
                </span>
                <el-form-item label="搜索：">
                  <el-input v-model="searchForm.name" placeholder="名称"></el-input>
                </el-form-item>
                <el-button type="primary" icon="el-icon-search" @click="searchSubmit">搜索</el-button>
              </div>
              <div class="uers-right">
                <span class="btn-r">
                  <el-button type="primary" plain icon="el-icon-plus" @click="addSubmit">新增</el-button>
                </span>
              </div>
            </el-form>
          </div>
          <div class="tabbox">
          <el-table
            :data="dataList"
            height="100%"
            border
            class="tabbox"
            ref="multipleTable"
            :header-cell-style="{background:'#f2f6fc',color:'#606266'}"
            @selection-change="handleSelectionChange"
          >
            <el-table-column type="selection" width="55" align="center"></el-table-column>
            <el-table-column prop="ID" label="ID" width="160" align="center">
              <template slot-scope="scope">
                <span>{{scope.row.ticketTypeId}}</span>
              </template>
            </el-table-column>
            <el-table-column prop="name" label="名称" width="160" align="center">
              <template slot-scope="scope">
                <span>{{scope.row.name}}</span>
              </template>
            </el-table-column>
            <el-table-column prop="price" label="价格" width="160" align="center">
              <template slot-scope="scope">
                <span>{{scope.row.price}}</span>
              </template>
            </el-table-column>
            <el-table-column prop="url" label="微信购票地址" align="center">
              <template slot-scope="scope">
                <div class="demo-image__preview">
                  {{url+'/wechat/buy/'+scope.row.ticketTypeId}}
                </div>
              </template>
            </el-table-column> 
            <el-table-column prop="startDate" label="开始时间"  width="160" align="center">
              <template slot-scope="scope">
                <span>{{scope.row.startDate}}</span>
              </template>
            </el-table-column>
            <el-table-column prop="endDate" label="结束时间" width="160"  align="center">
              <template slot-scope="scope">
                <span>{{scope.row.endDate}}</span>
              </template>
            </el-table-column>
            <el-table-column label="操作" width="160" align="center">
              <template slot-scope="scope">
                <el-button type="text" @click="handleEdit(scope.$index,scope.row)">编辑</el-button>
                <el-button type="text" class="red" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
              </template>
            </el-table-column>
          </el-table></div>
          <div class="fb"><el-pagination
            class="pag"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage"
            :page-sizes="[5, 10, 15, 20]"
            :page-size="pagesize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
            background
          ></el-pagination></div>
        </div>
        <DeleteDialog
          :delVisible="delVisible"
          @deleteData="deleteData"
          @handleCloseVisible="handleCloseVisible"
        ></DeleteDialog>
        <EditTicketManage :editShow="editShow" :editData="editData" @backFunStu="getFunStu"></EditTicketManage>
      </el-main>
    </el-container>
  </div>
</template>
<script>
import EditTicketManage from "../../../components/ticketing/ticket/EditTicketManage";
import DeleteDialog from "../../../components/public/DeleteConfim";

export default {
  data() {
    return {
      total: 0, //总条数
      currentPage: 1, //初始页
      pagesize: 10, // 每页的数据
      //表格高度适配
      tabheight: "",
      searchForm: {
        name: ""
      },
      editData: {},
      listShow: true,
      delVisible: false,
      ticketCom_Id: "",
      editShow: false,
      dataList: [],
      url:localStorage.getItem('url').replace('/api',''),
      url1:localStorage.getItem('url').replace('/api','')+'/wechat/from/'+localStorage.getItem('project_Id'),
      multipleSelection: [],
      productId:localStorage.getItem('project_Id')
    };
  },
  mounted() {
    // this.tabheight=(this.$refs.getheight.offsetHeight-165)
  },
  created() {
    this.searchSubmit(); 
  },
  methods: {
    handleSizeChange(val) {
      this.pagesize = val;
      this.searchSubmit();
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      console.log(`当前页: ${val}`);
      this.getData();
    },
    handleEdit(index, row) {
      this.editData = row;
      this.listShow = false;
      this.editShow = true;
    },
    searchSubmit() {
      var search = {
        name:this.searchForm.name,
        pageIndex:this.currentPage - 1,
        pageSize:this.pagesize,
        projectId:this.productId
      }
      this.$axios.post('/TicketType/Search',search)
        .then(res =>{
          if (res.data.hasError == false) {
            this.dataList = [...res.data.data]
            this.total = res.data.total;
          }
        })
    },
    addSubmit() {
      this.listShow = false;
      this.editShow = true;
    },
    handleDelete(index, row) {
      this.ticketCom_Id = row.ticketTypeId;
      this.delVisible = true;
    },
    deleteData() {
      this.$axios.delete(`/TicketType/${this.ticketCom_Id}`)
        .then(res =>{
            this.$message.success("删除成功！");
            this.delVisible = false
            this.getData();
        })
    },
    handleCloseVisible() {
      this.ticketCom_Id = "";
      this.delVisible = false;
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    getFunStu() {
      this.listShow = true;
      this.editShow = false;
      this.searchSubmit();
    }
  },
  components: {
    EditTicketManage,
    DeleteDialog
  }
};
</script>
<style lang="scss" scope>
.pag {
  position: absolute;
  bottom: 0;
}

.table-wrap {
  margin-left: 10px;
  height: 100%;
}
.el-main{
  border-radius: 5px;
  position: relative;
}
.uers-left {
  float: left;
}
.uers-right {
  float: right;
}
.el-dialog{height: auto;}
</style>